var app = getApp(),
  common = require("../../common/common.js");

Page({
  data: {

  },
  // 作业详情
  detailWorker(id,_t){

    app.util.request({
      url: 'entry/wxapp/detailWorker',
      data: {
        id: id,
      },
      method: 'POST',
      success: function (a) {
        console.log(a)
        _t.setData({
          classdetail: a.data.data
        })
      }
    })
  },
  // 提交作业列表
  studentWorker(id, _t) {
    app.util.request({
      url: 'entry/wxapp/correctWorks',
      data: {
        wid:id,
        // tid:wx.getStorageSync("users").tid
      },
      method: 'POST',
      success: function (a) {
        console.log(a)
        let student = a.data.data
        for (var i = 0; i < student.length;i++){
          student[i].active = false
        }
        _t.setData({
          student: student
        })
      }
    })
  },
  // 显示隐藏评分框
  showScore(e){
    console.log(e.currentTarget.dataset.ind)
    let _t = this
    let ind = e.currentTarget.dataset.ind
    _t.data.student[ind].active = !_t.data.student[ind].active
    _t.setData({
      student: _t.data.student
    })
  },
  // 提交评分内容
  studentAdd(w){
    console.log(w)
    let _t = this
    let content = w.detail.value.content
    let score = w.detail.value.score
    let tid = _t.data.classdetail.tid
    let id = w.currentTarget.dataset.id
    app.util.request({
      url: 'entry/wxapp/homeworkCorrecting',
      data: {
        tid: tid,
        score: score,
        id:id,
        content: content
      },
      method: 'POST',
      success: function (a) {
        console.log(a)
        if(a.data.errno == 0){
          wx.showToast({
            title: a.data.message,
            icon: 'none',            
            duration: 1500,
          })
        }
      }
    })
  },  
  
  onLoad: function(w) {
    let id = w.id
    let _t = this
    _t.detailWorker(id,_t)
    _t.studentWorker(id,_t)
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})